<!DOCTYPE html>
<html lang="en">
<head>

</head>
<body>
<form class="layui-form" lay-filter="person-form">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">时间范围</label>
            <div class="layui-input-inline">
                <input class="layui-input ares-w-auto" readonly id="person-date" placeholder=" - ">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">选择分组</label>
            <div class="layui-input-inline">
                <select name="person-group-select" lay-filter="person-group-select"></select>
            </div>
        </div>
    </div>
</form>
<table id="person-count-table" class="layui-hide" lay-filter="person-count-table"></table>

<script>
    $(function ($) {
        var defaultStartTime = +new Date().setMonth(new Date().getMonth() - 1),
            defaultEndTime = +new Date();

        renderTreatmentGroup('person-form', 'person-group-select');
        laydate.render({
            elem: '#person-date',
            btns: ['confirm'],
            range: true,
            value: dateFilters.dateFormat(defaultStartTime) + ' - ' + dateFilters.dateFormat(defaultEndTime),
            done: function (value, date, endDate) {
                var range = value.split(' - '),
                    groupId = form.val('person-form')['person-group-select'];
                personCount(groupId, +new Date(range[0]), +new Date(range[1]));
            }
        });
        form.on('select(person-group-select)', function (data) {
            var range = $('#person-date').val().split(' - '),
                groupId = data.value;
            personCount(groupId, +new Date(range[0]), +new Date(range[1]));
        });

        function personCount(groupId, startDate, endDate) {
            mandyServices.mandy_statistics_profile(groupId, startDate, endDate).then(function (res) {
                var data = res.data;
                var list = data.list || [];
                table.render({
                    elem: '#person-count-table',
                    data: list,
                    cellMinWidth: 80,
                    cols: [[
                        {title: '治疗师', field: 'therapist_name'},
                        {title: '分组', field: 'group_name'},
                        {title: '康复评估(次)', field: 'assess'},
                        {title: '评估完成率', field: 'assess_complete'},
                        {title: '康复训练(次)', field: 'trains'},
                        {title: '训练完成率', field: 'trains_complete'},
                        {title: '请假(小时)', field: 'vacation_hours'},

                        {
                            title: '最后修改时间', width: 150,
                            templet: function (d) {
                                return dateFilters.dateTimeFormat(d.last_update_time);
                            }
                        },
                    ]]
                });
            })
        }

        personCount(form.val('person-form')['person-group-select'], defaultStartTime, defaultEndTime);
    })
</script>
</body>
</html>